package ai.zixing.example03;

/**
 * 开奖服务
 */
public abstract class LotteryService {
    // 事件注入
    private final EventManager eventManager;

    public LotteryService() {
        // 设置事件类型
        eventManager = new EventManager(EventType.MQ, EventType.Message);
        // 订阅
        eventManager.subscribe(EventType.MQ, new MQEventListener());
        eventManager.subscribe(EventType.Message, new MessageEventListener());
    }

    public LotteryResult lotteryAndMsg(String uId) {
        LotteryResult result = lottery(uId);
        //发送通知
        eventManager.notify(EventType.Message, result);
        eventManager.notify(EventType.MQ, result);

        return result;
    }

    // 开奖结果
    public abstract LotteryResult lottery(String uId);
}
